#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@gosun>
#
# Distributed under terms of the MIT license.

"""

"""

def s2(n):
    s = 0

    for i in range(1, n+1):
        s += i*i

    print(s)
    s1= (1/3) * (n**3) + (1/2) * (n**2) + n/6
    print(s1)
    assert s == s1

    return s

def s1(n):
    return sum( range(1, n+1) )

def square_sum_varify(n):
    # 从1^2加到n^2

    # double 从1^2加到n^2
    double_sum = 0
    for i in range(1, n+1):
        double_sum += i**2
    double_sum *= 2

    # 第二种计算方式
    # double_sum2 = 0
    double_sum2 = ((n+1) ** 2) * n
    minus = 0
    # for i in range(1, n+1):
    #     minus += i * (n+1-i) * 2
    # minus = go_on_multiple(n)
    minus = go_on_descending_multiple_test(n)

    double_sum2 -= minus

    print(double_sum)
    print(double_sum2)

    assert double_sum == double_sum2

def go_on_multiple(n):
    s = 0
    for i in range(1, n+1):
        s += i * (n+1-i) * 2

    print('minus', s)
    return s

def go_on_descending_multiple_test(n):
    s = 0
    # for i in range(1, n+1):
    #     # s += i * (n+1-i) * 2
    #     s += i * (n-(i-1)) * 2

    #     # => 2: 1 * (n), 2 * (n-1), 3*(n-2), 4*(n-3), n*(n-(n-1))
    #     # => 2:(1...+n)*n - [ (0*1) + 1*2 + 2*3 + 3*4 + ... (n-1)*n]
    #     # => 2:s(n)*n - []
    #     # => 2:(n*(n+1))/2 - [ (0*1) + 1*2 + 2*3 + 3*4 + ... (n-1)*n]
    s = 2 *( n*(n+1)/2 * n  - go_on_ascending_multiple_test(n-1) )

    print('minus', s)
    return s

def go_on_ascending_multiple_test(n):
    # s = 0
    # for i in range(1, n+1):
    #     s += i * (i+1)
    #     # => 1*(1+1) + 2*(2+1) + 3*(3+1) + 4*(4+1) + n*(n+1)
    #     # => (1*1 + 2*2 + n*n) + (1+2+3+n)
    #     # => (1*1 + 2*2 + n*n) + s(n)
    #     # => s2(n) + s(n)
    # return s
    return s2(n) + s1(n)

def main():
    print("start main")
    # square_sum_varify(8)
    # s2(8)
    s2(7)

if __name__ == "__main__":
    main()
